﻿using System;
using System.Linq;
using System.Web.Security;
using MMSWebsite.DataAccessManagement;

namespace MMSWebsite.Business
{
    public class MyRoleProvider: RoleProvider
    {
        readonly EmployeeAccessProvider _eap = new EmployeeAccessProvider();
        public override bool IsUserInRole(string empCode, string roleName)
        {
            var emp = _eap.GetEmployeeByCode(empCode);
            var checkRole = emp.Roles.Where(x => x.Role.RoleName.ToLower().Contains(roleName.ToLower()));
            foreach (var roleWrapper in checkRole)
            {
                if (roleWrapper.RoleIsChecked) return true;
            }
            return false;
        }

        public override string[] GetRolesForUser(string empCode)
        {
            var emp = _eap.GetEmployeeByCode(empCode);
            var roles = (from role in emp.Roles where role.RoleIsChecked select role.Role.RoleName).ToList();
            return roles.ToArray();
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }

        public override void AddUsersToRoles(string[] username, string[] rolename)
        {

        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName { get; set; }
    }
}